﻿Type=Activity
Version=6
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Private mapview As GaodeMap2D
	Private lbltitle As Label
	Private mylocsty As MyLocationStyle
	Private CUF As CameraUpdateFactory
	Private btnleft As Label
	Private mList As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim telaw As telanywhere
telaw.Initialize(Activity)

	'Do not forget to load the layout file created with the visual designer. For example:
	'Activity.LoadLayout("Layout1")
	Activity.LoadLayout("laymapview")
	mapview.onCreate(Null)
	mylocsty.init
	comm.setFA(btnleft,"fa-angle-left","")
	'mylocsty.iconfrombmp(LoadBitmap(File.DirAssets,"ORANGE2d.png"))
	mylocsty.anchor(0.5,0.5)
	mylocsty.iconfromasset("ORANGE2d.png")
	mylocsty.strokeWidth(1)
	mylocsty.strokeColor(Colors.Black)
	mapview.MyLocationStyle=mylocsty
	'<!-- 定位需要的服务 使用2.0的定位需要加上这个 -->
    '<service android:name="com.amap.api.location.APSService"></service>
	mapview.MyLocationEnabled=True
	mapview.CompassEnabled=True
	mapview.changeCamera(CUF.zoomTo(14.0),True)'设置缩放级别
End Sub
Sub biaozhu(mplst As List,title As String)
	mList=mplst
	comm.L("mapsize:"&mplst.Size)
	For i=0 To mplst.Size-1
		Dim mp As MapPoint=mplst.Get(i)
		Dim mpo As MarkerOptions
		Dim pos As LatLng
		mpo.init
		mpo.icondefault
		pos.init(mp.lat,mp.lng)
		mpo.position(pos)
		mpo.anchor(0.5,0.5)
		mpo.draggable(False)
		comm.L(mp.poiname)
		mpo.title(mp.poiname).position(pos)
		If mp.tag.adWords.Length>0 And mp.tag.teacheAge>0 Then
			Dim str As String="性别："
			If mp.tag.sexMen Then str=str&"男" Else str=str&"女"
			'str=str&" 教龄："&mp.tag.teacheAge&"年"&CRLF&comm.str2mutiline(mp.tag.adWords,10)
			'暂时去掉简介
			str=str&" 教龄："&mp.tag.teacheAge&"年"
			mpo.snippet(str)	
		Else
			mpo.snippet(mp.poiname)
		End If
		mapview.addMarker(mpo)
	Next
	Dim mpo1 As MarkerOptions
	mpo1.init
	mpo1.icondefault2(mpo1.HUE_RED)
	Dim pos As LatLng
	pos.init(43.790947,87.60792)
	mpo1.position(pos)
'	tox.fontColor(Colors.Red)
'	tox.fontSize(20dip)
	mpo1.title("天山区客户服务中心")
	mpo1.snippet("乌鲁木齐市人民路2号乌鲁木齐大厦4楼A座,电话:09912573888")
	mapview.addMarker(mpo1)
	
	Dim pos As LatLng
	pos.init(43.883605,87.598207)
	Dim mpo1 As MarkerOptions
	mpo1.init
	mpo1.icondefault2(mpo1.HUE_RED).position(pos).title($"新市区客户服务中心"$).snippet("新市区鲤鱼山北路领世华府1号楼 2112室,电话:09916664610")
'	tox.fontColor(Colors.Red)
'	tox.fontSize(20dip)
	mapview.addMarker(mpo1.anchor(0.5,0.5))
	mapview.changeCamera(CUF.changeLatLng(pos),True)'移动镜头
	lbltitle.Text=title
End Sub
Sub Activity_Resume
	mapview.onResume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
	mapview.onPause
	If UserClosed Then mapview.ClearAllMarkerAndSoOn
End Sub
'如果返回true则拦截此事件
Sub mapview_OnMarkerClick(markerid As String,markertitle As String,markerpos As LatLng) As Boolean
'	Log("id:"&markerid&" title:"&markertitle&" pos:"&markerpos.lat&","&markerpos.lng)
'	Dim id As String=markerid.ToLowerCase.Replace("marker","") '转id
'	Log(id)
	Dim t As Teacher=findmarkertec(markertitle,markerpos.lat,markerpos.lng)
	If t.IsInitialized Then 
		CallSubDelayed2(Me,"askShowDetail",t)
	End If
	Return False
End Sub
Sub askShowDetail(t As Teacher)
	If Msgbox2("要打开 "&t.nickname&" 的详细资料吗?","查看详情","是","否","",Null)=DialogResponse.POSITIVE Then
		comm.showTecDetail(t.ID)
	End If
End Sub
'因为高德地图没有合适的字段存放唯一标识符，所以用多个条件匹配的方式在自己程序里查找，markerid并不能用
Sub findmarkertec(title As String,poslat As String,poslng As String) As Teacher
	Dim ret As Teacher
	For i=0 To mList.Size-1
		Dim mp As MapPoint=mList.Get(i)
		mp.lat=ProcessString2doubleString(mp.tag.lat)
		mp.lng=ProcessString2doubleString(mp.tag.lng)
		'自己marker的title为空
		If title<>Null And  mp.tag.nickname.CompareTo(title)=0 And mp.tag.lat.CompareTo(poslat)=0 And mp.tag.lng.CompareTo(poslng)=0 Then
			ret=mp.tag
			Log(ret)
			Return ret
		End If
	Next
	Return ret
End Sub
'处理尾部的0
Sub ProcessString2doubleString(str As String) As String
	Dim ret As Double=0
	If IsNumber(str) Then
		ret=str
	End If
	Return ret
End Sub
Sub mapview_onmapclick(pos As LatLng)
	'comm.TL(pos.lat&" "&pos.lng&" click")
End Sub

Sub ivback_Click
	Activity.Finish
End Sub
#If java
public void _onDestroy() {
		_mapview.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
	super.onSaveInstanceState(outState);
	_mapview.onSaveInstanceState(outState);
}
#end if